/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao.erp;

import com.openbravo.data.loader.TableDBSentenceBuilder;
import e.odbo.data.dao.ModifiedLogDAO;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.serialize.DataRead;
import com.openbravo.data.loader.serialize.DataWrite;
import com.openbravo.data.loader.serialize.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.ImageUtils;
import com.openbravo.data.loader.sentence.SentenceList;

import com.openbravo.data.loader.sentence.StaticSentence;
import com.openbravo.data.loader.table.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

import com.openbravo.pos.bean.erp.OrderTypeCategoryExt;

/**
 *
 * @author Administrator
 */
public class OrderTypeCategoryExtDAO extends ModifiedLogDAO<OrderTypeCategoryExt> {

    public OrderTypeCategoryExtDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(
                "ORDERTYPECATEGORIES",
                new Field[]{
                   new Field("ID",Datas.STRING, Formats.STRING,"Label.Name"),
                   new Field("NAME",Datas.STRING, Formats.STRING),
                   new Field("PARENTID",Datas.STRING, Formats.STRING),
                   new Field("IMAGE", Datas.IMAGE, Formats.NULL),
                   new Field("ISHOT",Datas.BOOLEAN, Formats.BOOLEAN,"label.categoryPanel.ishot"),
                   new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                } ,
                new int[]{0});
        
    }

    @Override
    public void writeInsertValues(DataWrite dp, OrderTypeCategoryExt obj) throws BasicException {
         dp.setString(1, obj.getID());
         dp.setString(2,obj.getName());
         dp.setString(3, obj.getM_sParentID());
         dp.setBytes(4, obj.getImage());
         dp.setBoolean(5, obj.isHot());
         dp.setTimestamp(6,obj.getLastModified());
    }

    public OrderTypeCategoryExt readValues(DataRead dr,OrderTypeCategoryExt obj) throws BasicException {
      if(obj==null)
    	 obj=  new OrderTypeCategoryExt();
        obj.setID(dr.getString(1));
	    obj.setName(dr.getString(2));
	    obj.setM_sParentID(dr.getString(3));
	    obj.setImage(dr.getBytes(4));
	    obj.setHot(dr.getBoolean(5));
		obj.setLastModified(dr.getTimestamp(6));
      return obj;
    }

    public SentenceList getOrderTypeCategoriesList() {
        return new StaticSentence(s, ((TableDBSentenceBuilder)getTableBuilder()).getListSQL(getTable())+" ORDER BY NAME", null, this);
    }

    @Override
    public Class getSuportClass() {
        return OrderTypeCategoryExt.class;
    }

}
